package cn.tedu.ivos2.vehicle.service.impl;

import cn.tedu.ivos2.vehicle.mapper.VehicleMapper;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos2.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos2.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos2.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos2.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author 边拾柱
 * @date 2025/1/4 16:43
 */
@Slf4j
@Service
public class VehicleServiceImpl implements VehicleService {

    @Autowired
    private VehicleMapper vehicleMapper;

    @Override
    public List<VehicleVO> selectVehicle(VehicleQuery vehicleQuery) {
        List<VehicleVO> vehicleVOS = vehicleMapper.selectVehicle(vehicleQuery);
        return vehicleVOS;
    }

    @Override
    public void saveVehicle(VehicleSaveParam vehicleSaveParam) {
//        "".substring(100);
        log.debug("保存车辆参数业务", vehicleSaveParam);
        Vehicle vehicle = new Vehicle();
        BeanUtils.copyProperties(vehicleSaveParam, vehicle);


        if (vehicle.getId() != null) {
            vehicle.setUpdateTime(new Date());
            vehicleMapper.update(vehicle);
        } else {
            vehicle.setCreateTime(new Date());
            vehicle.setStatus("1");
            vehicleMapper.insert(vehicle);
        }
    }

    @Override
    public void deleteVehicle(Long id) {
        log.debug("删除车辆业务操作，id={}", id);
        vehicleMapper.delete(id);
    }
}
